package com.softserveinc.autorent.model;

import java.io.Serializable;
import java.util.Arrays;

import javax.persistence.*;

@Entity
@Table(name="car_photo")
@NamedQueries({
@NamedQuery(name = "CarPhoto.findAll", query = "SELECT f FROM CarPhoto f"),
@NamedQuery(name = "CarPhoto.findById", query = "SELECT f FROM CarPhoto f WHERE f.id = :id"),
@NamedQuery(name = "CarPhoto.findAllByCarModelId", query = "SELECT f FROM CarPhoto f WHERE f.carModel.id = :id")
})
public class CarPhoto implements Serializable {

	private static final long serialVersionUID = 5026288860671437680L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(unique=true, nullable=false)
	private int id;

	@Column(name="file_name", nullable=true)
	@Lob
	private byte[] photo = null;
	
	private String description;

	//bi-directional many-to-one association to CarModel
	@ManyToOne
	@JoinColumn(name="car_model_id", nullable=true)
	private CarModel carModel;

	public CarPhoto() {
	}

	public CarPhoto(byte[] photo, String description,
			CarModel carModel) {
		this.photo = photo;
		this.description = description;
		this.carModel = carModel;
	}


	public CarPhoto(Integer uniqueId, String description2, byte[] buffer) {
		this.photo = buffer;
		this.description = description2;
		this.id = uniqueId;
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public CarModel getCarModel() {
		return this.carModel;
	}

	public void setCarModel(CarModel carModel) {
		this.carModel = carModel;
	}


	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	public byte[] getPhoto() {
		return photo;
	}

	public void setPhoto(byte[] photo) {
		this.photo = photo;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((carModel == null) ? 0 : carModel.hashCode());
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result + id;
		result = prime * result + Arrays.hashCode(photo);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CarPhoto other = (CarPhoto) obj;
		if (carModel == null) {
			if (other.carModel != null)
				return false;
		} else if (!carModel.equals(other.carModel))
			return false;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (id != other.id)
			return false;
		if (!Arrays.equals(photo, other.photo))
			return false;
		return true;
	}
	

}